package com.kermel.andromeda.data;

import java.util.Calendar;

import com.kermel.common.util.DateTimeUtils;

public class AlarmTimeModel {
    public int hour;
    public int minute;
    public AmPm amPM;
    public boolean militaryTime;
    
    public AlarmTimeModel() {
        hour = getCurrentHour();
        minute = getCurrentMinute();
        amPM = determineCurrentAmPm();
        militaryTime = true;
    }
    
    private int getCurrentHour() {
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        return hour;
    }
    
    private int getCurrentMinute() {
        int minute = Calendar.getInstance().get(Calendar.MINUTE);
        return minute;
    }
    
    private AmPm determineCurrentAmPm() {
        AmPm result = AmPm.AM;
        
        int currentAmPm = Calendar.getInstance().get(Calendar.AM_PM);
        
        if (currentAmPm == Calendar.AM)
            result = AmPm.AM;
        else
            result = AmPm.PM;
        
        return result;
    }
    
    public long getAlarmTimeInMillis() {
        Calendar today = Calendar.getInstance();
        today.set(Calendar.HOUR_OF_DAY, hour);
        today.set(Calendar.MINUTE, minute);
        today.set(Calendar.SECOND, 0);
        today.set(Calendar.MILLISECOND, 0);
        
        long triggerTime = today.getTimeInMillis();
        String triggerTimeString = DateTimeUtils.timeInMillisecondsToDateStringFull(triggerTime);
        System.out.println(String.format("AlarmTimeModel.triggerTime: %d (%s)", triggerTime, triggerTimeString));
        
        return triggerTime;
    }

}
